﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Dimas.Framework.Fake;
using Dimas.Framework.Interface;
using Dimas.Portal.Models;
using Dimas.Portal.Tests.Infrastraction;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StructureMap;

namespace Dimas.Portal.Tests
{
    [TestClass]
    public class UnitTestController : BaseUnitTest
    {
        [TestMethod]
        public void TestMethod()
        {
            var model = RunTest();
            var expectedCounter = 3;
            Assert.AreEqual(expectedCounter, model.Count);



        }
        [TestMethod]
        public void TestMethodWhenBrokenCache()
        {
            ObjectFactory.Configure(x =>
            {
                x.For<ICacheManager>().Use<FakeBrokenCacheManager>();

            });
            var model = RunTest();
            var containsNull = model.Contains(null);
            var expectedCounter = false;
            Assert.AreEqual(expectedCounter, containsNull);
        }

        private static List<SampleModel> RunTest()
        {
            var controller = new Controllers.SampleController();
            var request = new SampleModel() { Name = "Dima", Id = 1 };
            var result = controller.Provider(request) as ViewResult;
            var model = result.Model as List<SampleModel>;
            return model;
        }
    
    }
}
